package com.shiloop.flashlight;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

/**
 * Created by skiloop on 2014/9/4.
 */
public class SimpleButtonView extends AbstractFlashView {
    public SimpleButtonView(Context context) {
        super(context);
    }

    public SimpleButtonView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SimpleButtonView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    protected void inflateView(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.simple_button_layout,
                (ViewGroup) findViewById(R.id.simple_button_view));
        setControlButton((Button) view.findViewById(R.id.simple_control_button));
        setOrientation(LinearLayout.VERTICAL);
        setGravity(Gravity.CENTER);
        setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        addView(view);
    }

    @Override
    public void onFlashlightStatusChange(boolean isFlashLightOn) {
        getControlButton().setText(isFlashLightOn ? R.string.turn_off : R.string.turn_on);
        getControlButton().setBackgroundColor(getResources().
                getColor(isFlashLightOn ? R.color.button_on_color : R.color.button_off_color));
    }
}
